/* service */
import {
    getTaskQualityField,
    getTaskQualityFieldIsFreeServiceFee,
    getTaskQualityFieldIsFreeSparePartFee,
    getTaskDefaultQuality,
} from "@service/TaskQualityService.ts";
import { isEmpty } from '@src/util/type'

export default {
    name: "quality-mixin",
    props: {
        taskFields: {
            type: Array
        },
        qualityInfo: {
            type: Object
        },
    },
    computed: {
        isFreeServiceFee() {
            let isFreeServiceFee = false
            if (this.isEmptyQuality && this.defaultQuality == "IN" ) {
                isFreeServiceFee = true
                sessionStorage.setItem('isFreeServiceFee', JSON.stringify(isFreeServiceFee));
                return true
            }
            isFreeServiceFee = this.qualityInfo?.qualityStatus == 'OUT' ? false : getTaskQualityFieldIsFreeServiceFee(this.taskQualityField)
            sessionStorage.setItem('isFreeServiceFee', JSON.stringify(isFreeServiceFee));
            return isFreeServiceFee
        },
        isFreeSparePartFee() {
            let isFreeSparePartFee = false
            if (this.isEmptyQuality && this.defaultQuality == "IN" ) {
                isFreeSparePartFee = true
                sessionStorage.setItem('isFreeSparePartFee', JSON.stringify(isFreeSparePartFee));
                return true
            }
            isFreeSparePartFee = this.qualityInfo?.qualityStatus == 'OUT' ? false : getTaskQualityFieldIsFreeSparePartFee(this.taskQualityField);
            sessionStorage.setItem('isFreeSparePartFee',  JSON.stringify(isFreeSparePartFee));
            return isFreeSparePartFee;
        },
        isFreeMaterialFee() {
            let isFreeMaterialFee = false
            if (this.isEmptyQuality && this.defaultQuality == "IN" ) {
                isFreeMaterialFee = true
                sessionStorage.setItem('isFreeMaterialFee', JSON.stringify(isFreeMaterialFee));
                return true
            }
            isFreeMaterialFee = this.taskQualityField && getTaskQualityFieldIsFreeSparePartFee(this.taskQualityField);
            sessionStorage.setItem('isFreeMaterialFee',  JSON.stringify(isFreeMaterialFee));
            return isFreeMaterialFee;
        },
        defaultQuality() {
            return getTaskDefaultQuality(this.taskQualityField) || "OUT";
        },
        isEmptyQuality() {
            // 老产品质保信息为空，没有质保状态，走系统默认配置
            // 新产品没有设置质保结束日期，没有质保状态，走系统默认配置
            return isEmpty(this.qualityInfo?.qualityStatus);
        },
        taskQualityField() {
            return getTaskQualityField(this.taskFields);
        },
    },
};
